home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 1).ISO / Shware / Base Golf / BaseGolf.exe / {app} / BaseGolf.exe / ntpath.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2002-11-28  |  8.9 KB  |  352 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.1)
  3.  
  4. import os
  5. import stat
  6. __all__ = [
  7.     'normcase',
  8.     'isabs',
  9.     'join',
  10.     'splitdrive',
  11.     'split',
  12.     'splitext',
  13.     'basename',
  14.     'dirname',
  15.     'commonprefix',
  16.     'getsize',
  17.     'getmtime',
  18.     'getatime',
  19.     'islink',
  20.     'exists',
  21.     'isdir',
  22.     'isfile',
  23.     'ismount',
  24.     'walk',
  25.     'expanduser',
  26.     'expandvars',
  27.     'normpath',
  28.     'abspath',
  29.     'splitunc']
  30.  
  31. def normcase(s):
  32.     return s.replace('/', '\\').lower()
  33.  
  34.  
  35. def isabs(s):
  36.     s = splitdrive(s)[1]
  37.     if s != '':
  38.         pass
  39.     return s[:1] in '/\\'
  40.  
  41.  
  42. def join(a, *p):
  43.     path = a
  44.     for b in p:
  45.         if isabs(b):
  46.             path = b
  47.         elif path == '' or path[-1:] in '/\\:':
  48.             path = path + b
  49.         else:
  50.             path = path + '\\' + b
  51.     
  52.     return path
  53.  
  54.  
  55. def splitdrive(p):
  56.     if p[1:2] == ':':
  57.         return (p[0:2], p[2:])
  58.     
  59.     return ('', p)
  60.  
  61.  
  62. def splitunc(p):
  63.     if p[1:2] == ':':
  64.         return ('', p)
  65.     
  66.     firstTwo = p[0:2]
  67.     if firstTwo == '//' or firstTwo == '\\\\':
  68.         normp = normcase(p)
  69.         index = normp.find('\\', 2)
  70.         if index == -1:
  71.             return ('', p)
  72.         
  73.         index = normp.find('\\', index + 1)
  74.         if index == -1:
  75.             index = len(p)
  76.         
  77.         return (p[:index], p[index:])
  78.     
  79.     return ('', p)
  80.  
  81.  
  82. def split(p):
  83.     (d, p) = splitdrive(p)
  84.     i = len(p)
  85.     while i and p[i - 1] not in '/\\':
  86.         i = i - 1
  87.     (head, tail) = (p[:i], p[i:])
  88.     head2 = head
  89.     while head2 and head2[-1] in '/\\':
  90.         head2 = head2[:-1]
  91.     if not head2:
  92.         pass
  93.     head = head
  94.     return (d + head, tail)
  95.  
  96.  
  97. def splitext(p):
  98.     (root, ext) = ('', '')
  99.     for c in p:
  100.         if c in [
  101.             '/',
  102.             '\\']:
  103.             (root, ext) = (root + ext + c, '')
  104.         elif c == '.':
  105.             if ext:
  106.                 (root, ext) = (root + ext, c)
  107.             else:
  108.                 ext = c
  109.         elif ext:
  110.             ext = ext + c
  111.         else:
  112.             root = root + c
  113.     
  114.     return (root, ext)
  115.  
  116.  
  117. def basename(p):
  118.     return split(p)[1]
  119.  
  120.  
  121. def dirname(p):
  122.     return split(p)[0]
  123.  
  124.  
  125. def commonprefix(m):
  126.     if not m:
  127.         return ''
  128.     
  129.     prefix = m[0]
  130.     for item in m:
  131.         for i in range(len(prefix)):
  132.             pass
  133.         
  134.     
  135.     return prefix
  136.  
  137.  
  138. def getsize(filename):
  139.     st = os.stat(filename)
  140.     return st[stat.ST_SIZE]
  141.  
  142.  
  143. def getmtime(filename):
  144.     st = os.stat(filename)
  145.     return st[stat.ST_MTIME]
  146.  
  147.  
  148. def getatime(filename):
  149.     st = os.stat(filename)
  150.     return st[stat.ST_ATIME]
  151.  
  152.  
  153. def islink(path):
  154.     return 0
  155.  
  156.  
  157. def exists(path):
  158.     
  159.     try:
  160.         st = os.stat(path)
  161.     except os.error:
  162.         return 0
  163.  
  164.     return 1
  165.  
  166.  
  167. def isdir(path):
  168.     
  169.     try:
  170.         st = os.stat(path)
  171.     except os.error:
  172.         return 0
  173.  
  174.     return stat.S_ISDIR(st[stat.ST_MODE])
  175.  
  176.  
  177. def isfile(path):
  178.     
  179.     try:
  180.         st = os.stat(path)
  181.     except os.error:
  182.         return 0
  183.  
  184.     return stat.S_ISREG(st[stat.ST_MODE])
  185.  
  186.  
  187. def ismount(path):
  188.     (unc, rest) = splitunc(path)
  189.     if unc:
  190.         return rest in ('', '/', '\\')
  191.     
  192.     p = splitdrive(path)[1]
  193.     if len(p) == 1:
  194.         pass
  195.     return p[0] in '/\\'
  196.  
  197.  
  198. def walk(top, func, arg):
  199.     
  200.     try:
  201.         names = os.listdir(top)
  202.     except os.error:
  203.         return None
  204.  
  205.     func(arg, top, names)
  206.     exceptions = ('.', '..')
  207.     for name in names:
  208.         if name not in exceptions:
  209.             name = join(top, name)
  210.             if isdir(name):
  211.                 walk(name, func, arg)
  212.             
  213.         
  214.     
  215.  
  216.  
  217. def expanduser(path):
  218.     if path[:1] != '~':
  219.         return path
  220.     
  221.     (i, n) = (1, len(path))
  222.     while i < n and path[i] not in '/\\':
  223.         i = i + 1
  224.     if i == 1:
  225.         if os.environ.has_key('HOME'):
  226.             userhome = os.environ['HOME']
  227.         elif not os.environ.has_key('HOMEPATH'):
  228.             return path
  229.         else:
  230.             
  231.             try:
  232.                 drive = os.environ['HOMEDRIVE']
  233.             except KeyError:
  234.                 drive = ''
  235.  
  236.             userhome = join(drive, os.environ['HOMEPATH'])
  237.     else:
  238.         return path
  239.     return userhome + path[i:]
  240.  
  241.  
  242. def expandvars(path):
  243.     if '$' not in path:
  244.         return path
  245.     
  246.     import string
  247.     varchars = string.letters + string.digits + '_-'
  248.     res = ''
  249.     index = 0
  250.     pathlen = len(path)
  251.     while index < pathlen:
  252.         c = path[index]
  253.         if c == "'":
  254.             path = path[index + 1:]
  255.             pathlen = len(path)
  256.             
  257.             try:
  258.                 index = path.index("'")
  259.                 res = res + "'" + path[:index + 1]
  260.             except ValueError:
  261.                 res = res + path
  262.                 index = pathlen - 1
  263.  
  264.         elif c == '$':
  265.             if path[index + 1:index + 2] == '$':
  266.                 res = res + c
  267.                 index = index + 1
  268.             elif path[index + 1:index + 2] == '{':
  269.                 path = path[index + 2:]
  270.                 pathlen = len(path)
  271.                 
  272.                 try:
  273.                     index = path.index('}')
  274.                     var = path[:index]
  275.                     if os.environ.has_key(var):
  276.                         res = res + os.environ[var]
  277.                 except ValueError:
  278.                     res = res + path
  279.                     index = pathlen - 1
  280.  
  281.             else:
  282.                 var = ''
  283.                 index = index + 1
  284.                 c = path[index:index + 1]
  285.                 while c != '' and c in varchars:
  286.                     var = var + c
  287.                     index = index + 1
  288.                     c = path[index:index + 1]
  289.                 if os.environ.has_key(var):
  290.                     res = res + os.environ[var]
  291.                 
  292.                 if c != '':
  293.                     res = res + c
  294.                 
  295.         else:
  296.             res = res + c
  297.         index = index + 1
  298.     return res
  299.  
  300.  
  301. def normpath(path):
  302.     path = path.replace('/', '\\')
  303.     (prefix, path) = splitdrive(path)
  304.     while path[:1] == '\\':
  305.         prefix = prefix + '\\'
  306.         path = path[1:]
  307.     comps = path.split('\\')
  308.     i = 0
  309.     while i < len(comps):
  310.         if comps[i] == '.':
  311.             del comps[i]
  312.         elif comps[i] == '..' and i > 0 and comps[i - 1] not in ('', '..'):
  313.             del comps[i - 1:i + 1]
  314.             i = i - 1
  315.         elif comps[i] == '' and i > 0 and comps[i - 1] != '':
  316.             del comps[i]
  317.         else:
  318.             i = i + 1
  319.     if not prefix and not comps:
  320.         comps.append('.')
  321.     
  322.     return prefix + '\\'.join(comps)
  323.  
  324.  
  325. def abspath(path):
  326.     global abspath
  327.     
  328.     try:
  329.         import win32api
  330.     except ImportError:
  331.         
  332.         def _abspath(path):
  333.             if not isabs(path):
  334.                 path = join(os.getcwd(), path)
  335.             
  336.             return normpath(path)
  337.  
  338.         abspath = _abspath
  339.         return _abspath(path)
  340.  
  341.     if path:
  342.         
  343.         try:
  344.             path = win32api.GetFullPathName(path)
  345.         except win32api.error:
  346.             pass
  347.  
  348.     else:
  349.         path = os.getcwd()
  350.     return normpath(path)
  351.  
  352.